package com.cai.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.cai.dao.AddressDao;
import com.cai.entity.PageResult;
import com.cai.entity.QueryPageBean;
import com.cai.pojo.Address;
import com.cai.service.AddressService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


@Service(interfaceClass = AddressService.class)
@Transactional
public class AddressServiceImpl implements AddressService {
    @Autowired
    private AddressDao addressDao;
    //地址分页查询
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        //使用分页助手
        PageHelper.startPage(currentPage, pageSize);
        Page<Address> page = addressDao.selectByCondition(queryString);
        long total = page.getTotal();
        List<Address> rows = page.getResult();
        return new PageResult(total, rows);
    }

    public List<Address> findAll() {
        return addressDao.findAll();
    }

    public void delete(Integer id) {
      addressDao.delete(id);
    }

    public void add(Address address) {
        addressDao.add(address);
    }
}
